/**
 * Created by dio on 2017/2/21 0021.
 */
import React from "react";
import {ScrollView, View} from "react-native";
import chjStyle from "../../../CustomStyle";
import ModuleCommonHeader from "../../module/ModuleCommonHeader";
import Util from "../../Util";
import WarrantyStartCheck from "./WarrantyStartCheck";
import SingleSelectionTextItem from "../common/SingleSelectionTextItem";
import NextButton from "../common/NextButton";
import {ActionConst, Actions} from "react-native-router-flux";

export default class PluginEngineCheck extends React.Component {
    // 构造函数，可执行初始化操作
    constructor(props) {
        super(props);
        // 在ES6，在构造函数里初始化state
        this.state = {};
        if (!Util.selectCar.pluginenginecheck) {
            Util.selectCar.pluginenginecheck = [
                {value: "正常", name: "启动马达检查"},
                {value: "正常", name: "发电机检查"},
                {value: "正常", name: "水箱箱体检查"},
                {value: "正常", name: "风扇检查"},
                {value: "正常", name: "水泵检查"},
                {value: "正常", name: "张紧轮、惰轮检查"},
                {value: "正常", name: "助力泵检查"}
            ];
        }
    }

    // 组件被加载时
    componentDidMount() {

    }

    // 组件即将被卸载时
    componentWillUnmount() {
    }

    // 组件被渲染时
    render() {
        return (
            <View style={chjStyle.mainContainer}>
                <ModuleCommonHeader title='发动机外挂件检查(03)' leftText='返回' clickedRight={this.clickedNew.bind(this)}
                                    rightText='保存'/>
                <ScrollView
                    style={chjStyle.mainList}>
                    {
                        Util.selectCar.pluginenginecheck.map((item, i) => this.renderItem(item, i))
                    }
                </ScrollView>
                <NextButton onClickedListener={() => this.clickedNew()}/>
            </View>
        );
    }

    renderItem(item, i) {
        return (<SingleSelectionTextItem object={item}
                                         optionArray={[{name: "正常"}, {name: "异响"}, {name: "拆装"}, {name: "其它"}]}/>);
    }


    clickedNew() {
        Util.saveData('cars', Util.selectCar);
        Actions.WarrantyStartCheck(
            {
                type: ActionConst.PUSH_OR_POP,
                name: 'WarrantyStartCheck',
                component: WarrantyStartCheck,
            }
        );
    }
}